package com.tyk.bookstore.front.product.service.impl;


import com.tyk.bookstore.front.common.cache.anno.ICache;
import com.tyk.bookstore.front.common.cache.constant.CacheConstant;
import com.tyk.bookstore.front.common.core.model.query.SuggestionQuery;
import com.tyk.bookstore.front.common.core.model.vo.SuggestionVo;
import com.tyk.bookstore.front.product.model.entity.PublisherDo;
import com.tyk.bookstore.front.product.repository.PublisherRepository;
import com.tyk.bookstore.front.product.service.PublisherService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.List;

/**
 * @author tyk
 * @description 出版社管理
 */
@Service
@RequiredArgsConstructor
public class PublisherServiceImp implements PublisherService {

    private final PublisherRepository publisherRepository;

    @Override
@ICache(
        prefix = CacheConstant.PUBLISHER_SUGGESTION_PREFIX,
        expireTime = CacheConstant.PUBLISHER_SUGGESTION_EXPIRE_TIME,
        lockPrefix = CacheConstant.PUBLISHER_SUGGESTION_LOCK_PREFIX
)
public List<SuggestionVo> getSuggestionList(SuggestionQuery query) {
    return publisherRepository.<BigInteger, String>selectBinList1Like(
                    PublisherDo::getId, PublisherDo::getName,
                    PublisherDo::getName, query.getNameLike(),
                    PublisherDo.class
            ).stream().map(it -> new SuggestionVo(it.getV1().longValue(), it.getV2()))
            .toList();
}

}
